﻿#region

using System.Collections.Generic;
using System.Linq;
using CuongHanh.Context;
using CuongHanh.DAL;
using CuongHanh.Models;

#endregion

namespace CuongHanh.Service
{
    public class TiGiaServce
    {
        public static bool Update(TiGia newModel)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                TiGia model = unitOfWork.GetById<TiGia>(newModel.Code);
                if(model != null)
                {
                    model.UpdateInfoFrom(newModel);
                    unitOfWork.Save();
                    CacheStringKey<TiGia>.Singleton.UpdateCached(model);

                }
                else
                {
                    unitOfWork.Insert(newModel);
                    unitOfWork.Save();
                    CacheStringKey<TiGia>.Singleton.UpdateCached(newModel);
                }
            }
            return true;
        }

    }
}
